package com.lin.manager.notice.message;

import com.lin.manager.common.enums.NoticeEnum;
import com.lin.manager.notice.model.dto.NoticeDTO;
import com.lin.manager.sms.model.dto.SmsDTO;
import com.lin.manager.sms.service.SendFaceService;
import com.lin.manager.system.entity.SysUserEntity;
import com.lin.manager.system.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @作者: 林江
 * @创建时间: 2024/4/10
 * @功能: 短信消息
 */
@Slf4j
@Component
public class SmsNoticeMessage implements NoticeMessage {
    @Resource
    SysUserService userService;

    @Resource
    SendFaceService sendFaceService;

    @Override
    public void send(NoticeDTO dto) {
        if (dto.getSendStatus().equals(NumberUtils.INTEGER_TWO)) {
            // 推送到rabbitmq中
        } else {
            List<SysUserEntity> users = userService.getByIds(dto.getUserIds());

            SmsDTO smsDto = new SmsDTO();
            smsDto.setPhoneNums(users.stream().map(SysUserEntity::getPhone).collect(Collectors.toList()));

            Map<String, Object> map = new HashMap<>();
            map.put("title", dto.getTitle());
            map.put("content", dto.getContent());
            smsDto.setVariableParam(map);

            sendFaceService.sendSms(smsDto);
        }
    }

    @Override
    public NoticeEnum getSendType() {
        return NoticeEnum.SMS_NOTICE;
    }
}
